<%@ page import="com.entity.Working" %>
<%@ page import="com.util.MybatisUtil" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page import="com.dao.WorkingMapper" %>
<%@ page import="org.apache.ibatis.session.SqlSession" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>添加</title>
</head>
<%
    SqlSession sqlSession = null;
    Working working = null;
    int id =Integer.parseInt( request.getParameter("id"));
    try {
        sqlSession=MybatisUtil.createSqlSession();
        working=sqlSession.getMapper(WorkingMapper.class).getWorking(id);

    }catch (Exception e){
        e.printStackTrace();
    }finally {
        MybatisUtil.closeSqlSession(sqlSession);
    }
    request.setAttribute("w", working);
%>
<script src="jquery-1.12.4.js"></script>
<script>
$(function(){
	$("input").blur(function(){
		var title=$("#title").val();
		$.ajax({
			"url"		:"User",
			"type"		:"POST",
			"data"		:"title="+title,
			"dataType"	:"text",
			"success"	:callBack,
			"error"		:function(){
				alert("用户名验证时出现错误，请稍后再试或与管理员联系！");
			}
		});
		function callBack(data){
			if (data=="true") {
				$("span").html("标题已使用");
				$("#bott").hide();
			} else{
				$("span").html("标题可以使用");
				$("#bott").show();
				
			}
		}
	})
	
	$("form").submit(function(){
		var title = $("#title").val();
		var content = $("#content").val();
		var type = $("#type").val();
		if(title==""){
			alert("请输入标题");
			return false;
		}else if(content==""){
			alert("请输入内容");
			return false;
		}else if(type==0){
			alert("请输入类别");
			return false;
		}
	})
})

</script>
<body>
<form action="Per?pre=up" method="post" style="line-height: 50px;text-align: center;">
    <div id="" style="height: 350px;width: 500px;margin: auto;border: 1px solid;">
        <h1 style="text-align: center;">我的工作笔记</h1>
        <input type="hidden" name="id" value="${w.id}">
        标签：<input type="text" name="title" id="title"  value="${w.title}"><span></span><br />
        内容：<textarea name="content" id="content" rows="5" cols="30">${w.content}</textarea><br />
        类别：<select name="type" id="type" style="margin-left: 50px;">
        <option value="0">--请选择类别--</option>
        <option value="1" <c:if test="${w.type==1}">selected</c:if>>技术</option>
        <option value="2" <c:if test="${w.type==2}">selected</c:if>>行政</option>
        <option value="3" <c:if test="${w.type==3}">selected</c:if>>人事</option>
    </select>
    </div>
    <input type="submit" id="bott" value="提交"/>
    <input type="button" onclick="history.back();" value="返回"/>
</form>
</body>
</html>